package rs.pnv.model.user;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotBlank;

import rs.pnv.model.AbstractEntity;

@Entity
@Table(name = "SEP_USERS")
@XmlAccessorType(XmlAccessType.FIELD)
public class User extends AbstractEntity {

	@NotBlank
	@Column(nullable = false, unique = true)
	@XmlElement(nillable = false)
	private String username;

	@NotBlank
	@Column(nullable = false)
	@XmlElement(nillable = false)
	private String password;

	private String firstname;

	private String lastname;

	@NotBlank
	@Column(nullable = false)
	@XmlElement(nillable = false)
	private String jmbg;

	@NotBlank
	@Column(nullable = false)
	@XmlElement(nillable = false)
	private String passportNumber;

	@NotBlank
	@Column(nullable = false)
	@XmlElement(nillable = false)
	private String address;

	private String phoneNumber;

	private Boolean contractor = false;

	@Email
	@NotBlank
	@Column(nullable = false)
	@XmlElement(nillable = false)
	private String email;

	public User() {

	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getFirstname() {
		return firstname;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	public String getLastname() {
		return lastname;
	}

	public void setLastname(String lastname) {
		this.lastname = lastname;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getJmbg() {
		return jmbg;
	}

	public void setJmbg(String jmbg) {
		this.jmbg = jmbg;
	}

	public String getPassportNumber() {
		return passportNumber;
	}

	public void setPassportNumber(String passportNumber) {
		this.passportNumber = passportNumber;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getPhoneNumber() {
		return phoneNumber;
	}

	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	public Boolean getContractor() {
		return contractor;
	}

	public void setContractor(Boolean contractor) {
		this.contractor = contractor;
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder()
				.append(username)
				.append(firstname)
				.append(lastname)
				.append(jmbg)
				.append(passportNumber)
				.append(address)
				.append(phoneNumber)
				.append(contractor)
				.append(email)
				.appendSuper(super.hashCode())
				.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (obj == this) {
			return true;
		}
		if (obj.getClass() != getClass()) {
			return false;
		}

		final User otherUser = (User) obj;

		return new EqualsBuilder()
				.append(username, otherUser.getUsername())
				.append(firstname, otherUser.getFirstname())
				.append(lastname, otherUser.getLastname())
				.append(jmbg, otherUser.getJmbg())
				.append(passportNumber, otherUser.getPassportNumber())
				.append(address, otherUser.getAddress())
				.append(phoneNumber, otherUser.getPhoneNumber())
				.append(contractor, otherUser.getContractor())
				.append(email, otherUser.getEmail())
				.appendSuper(super.equals(obj))
				.isEquals();
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
				.append("username", username)
				.append("firstname", firstname)
				.append("lastname", lastname)
				.append("jmbg", jmbg)
				.append("passportNumber", passportNumber)
				.append("address", address)
				.append("phoneNumber", phoneNumber)
				.append("contractor", contractor)
				.append("email", email)
				.append(super.toString())
				.toString();
	}

}
